package rd.hardcore.ui.config 
{
	import aze.motion.easing.Quadratic;
	import aze.motion.eaze;
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.filters.DropShadowFilter;
	import flash.geom.Rectangle;
	import fr.digitas.flowearth.conf.Conf;
	import rd.hardcore.ui.config.content.ConfigPanelContent;
	import rd.hardcore.ui.config.nav.Nav;
	/**
	 * ...
	 * @author Romain Prache
	 */
	public class ConfigPanel extends Sprite
	{
		static public const UPDATE : String = "content_update";
		
		private var bar 		: ConfigPanelBar;
		private var isOpen 		: Boolean;
		private var display		: Shape;
		private var body		: Shape;
		private var container	: Sprite;
		
		private var nav			: Nav;
		private var content		: ConfigPanelContent;
		
		private var _scrollRectHeight:Number = 0;
		
		public function ConfigPanel() 
		{
			x = 20;
			y = 70;
			alpha = 0;
			
			display = new Shape();
			display.graphics.beginFill(0xFF0000, .5);
			display.graphics.drawRoundRectComplex(0, 0, 760, 260, 0, 0, 13, 13);
			display.graphics.endFill();
			addChild(display);
			
			container = new Sprite();
			container.y = -250;
			addChild(container);
			
			body = new Shape();
			body.graphics.beginFill(0x111111, .9);
			body.graphics.drawRect(0, 0, 760, 260);
			body.graphics.endFill();
			container.addChild(body);
			
			container.mask = display;
			
			bar = new ConfigPanelBar();
			bar.y = 250;
			container.addChild(bar);
			
			bar.addEventListener(MouseEvent.CLICK, handleClick);
			
			// nav & content
			nav = new Nav();
			
			container.addChild(nav);
			content = new ConfigPanelContent();
			content.proxyNav = nav;
		}
		
		public function init() : void
		{
			content.build();
			nav.build();
			
			addEventListener(UPDATE, content.update);
		}
		
			
		private function handleClick(e:MouseEvent):void 
		{
			isOpen = !isOpen;
			
			if (isOpen)
			{
				eaze(container).to(.5, { y:0 } ).easing(Quadratic.easeOut);
				bar.open();
				
				container.addChild(content);
			} else {
				
				eaze(container).to(.4, { y: -250 } ).easing(Quadratic.easeIn).onComplete(clearContent);
				bar.close();
			}
			
		}
		
		private function clearContent():void
		{
			if (container.contains(content))	container.removeChild(content);
		}
		
		public function get scrollRectHeight():Number { return _scrollRectHeight; }
		
		public function set scrollRectHeight(value:Number):void 
		{
			_scrollRectHeight = value;
			this.scrollRect = new Rectangle(0, 0, bar.width, _scrollRectHeight );
		}
		
		
		
	}

}